package com.example.composestudy.router.part1

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavGraph
import com.example.composestudy.router.RouterConfig
import com.example.composestudy.router.TAG

@Composable
fun WelcomePager(navController: NavController) {
    Scaffold(
        topBar = {
            TopAppBar(
                title = { Text("欢迎") },
                /*navigationIcon = {
                    Button(onClick = {
                        // 会进入一个空白页面
                        // backQueue(当前后退堆栈)：2
                        // navController.popBackStack()

                        // 不会进入空白页面
                        // destinationCountOnBackStack(后退堆栈上的非导航图目标数): 1。不为1时调用popBackStack()
                        navController.navigateUp()
                    }) {
                        Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "返回")
                    }
                }*/
            )
        },
    ) { innerPadding ->
        // innerPadding = PaddingValues(start=0.0.dp, top=0.0.dp, end=0.0.dp, bottom=0.0.dp)
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center,
            modifier = Modifier
                .fillMaxSize()
                .padding(16.dp)
                .padding(innerPadding)
        ) {
            Button(onClick = {
                navController.navigate(RouterConfig.LOGIN)
            }) {
                Text("进入登录页")
            }
        }
    }
    Log.d(TAG, "WelcomePager: 堆栈信息：\n" +
            "backQueue(当前后退堆栈)：${navController.backQueue.size}\n" +
            "destinationCountOnBackStack(后退堆栈上的非导航图目标数): ${
                navController.backQueue.count { entry ->
                    entry.destination !is NavGraph
                }
            }")
}